//package com.mzq.langchain4j_springboot.config;
//
//import jakarta.servlet.ServletContext;
//import jakarta.servlet.http.HttpServletRequest;
//import org.springframework.context.ApplicationContext;
//import org.springframework.web.context.request.RequestAttributes;
//import org.springframework.web.context.request.RequestContextHolder;
//import org.springframework.web.context.request.ServletRequestAttributes;
//import org.springframework.web.context.support.WebApplicationContextUtils;
//
//public class BeanUtils {
//    public static Object getBean(Class clas){
//        HttpServletRequest request = ((ServletRequestAttributes) getRequestAttributesSafely()).getRequest();
//        ServletContext servletContext = request.getSession().getServletContext();
//        ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(servletContext);
//        return ac.getBean(clas);
//    }
//    public static RequestAttributes getRequestAttributesSafely(){
//        RequestAttributes requestAttributes = null;
//        try{
//            requestAttributes = RequestContextHolder.currentRequestAttributes();
//        }catch (IllegalStateException e){
//            requestAttributes = new NonWebRequestAttributes();
//        }
//        return requestAttributes;
//    }
//
//}